package p23_类型转换与绑定;

import org.springframework.core.GenericTypeResolver;

import java.lang.reflect.ParameterizedType;
import java.lang.reflect.Type;
import java.util.Arrays;

/**
 * 小技巧，如何获取泛型参数？
 */
public class _3_获取泛型参数 {

    public static void main(String[] args) {
        //1.jdk提供的api
        Type type = Student.class.getGenericSuperclass();
        if (type instanceof ParameterizedType parameterizedType) {
            System.out.println(Arrays.toString(parameterizedType.getActualTypeArguments()));
        }

        //2.spring提供的api(对jdk的api进行的封装)
        Class<?> aClass = GenericTypeResolver.resolveTypeArgument(Student.class, Person.class);
        System.out.println(aClass);
    }

    static class Person<T> {

    }

    static class Student extends Person<String> {

    }
}
